from django.shortcuts import render
from django.core import paginator
from django.db.models.query import QuerySet
from django.shortcuts import get_object_or_404, render
from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from .models import News


def index(request):

    newses = News.objects.order_by('-news_published_date')

    paginator = Paginator(newses, 3)
    page = request.GET.get('page')
    paged_newses = paginator.get_page(page)
    
    context = {
        'newses': paged_newses
    }
    return render(request, 'news/news.html', context)

# def news(request, news_id):
#     news = get_object_or_404(News, pk=news_id)

#     context = {
#         'news' : news
#     }
#     return render(request, 'news/news.html', context)